<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('快递发货')" />
</head>
<link  rel="stylesheet" th:href="@{/css/chosen/chosen.css}">
<link href="/css/print.css" type="text/css" rel="stylesheet" th:href="@{/css/print.css}"/>
		<style type="text/css">
			.form-control { display: inline-block;width: 50%}
		</style>
<body class="gray-bg">
	<div class="main" style="line-height: 35px">
			<div class="info01 bd" style="width: 70%;height: 70%;margin: auto;">
				<div class="fold head">兑换概况</div>
				<div class="row">
				  <div class="col-sm-6">兑换编号：<span th:text="${delivery.ordersId}"></span></div>
				  <div class="col-sm-6">兑换状态：<span>未发货</span></div>
				</div>
				<div class="row">
				  <div class="col-sm-6">兑换时间：<span th:text="${#dates.format(delivery.createdDate, 'yyyy-MM-dd hh:mm:ss')}"></span></div>
				</div>
			</div>
			<div class="info04 bd" style="width: 70%;margin: auto;">
				<div class="fold head">物流信息</div>
				<div class="row">
				  <div class="col-sm-6">物流单号：
					  <input class="form-control w-300"
							 placeholder="请填写物流单号"
							 id="number"
							 onblur="KdApiOrderDistinguish(this)">
				  </div>
					<div class="col-sm-6">物流公司：
						<select id="logisticsName" data-placeholder="选择物流公司" class="form-control chosen-select w-300" tabindex="2" style="z-index:3147483647">
							<option value="">选择物流公司</option>
							<option th:each="logistic:${logistics}" th:value="${logistic.logisticsName}" th:text="${logistic.logisticsName}"></option>
						</select></div>
				</div>
				<div class="row">
				  <div class="col-sm-6">收&nbsp;&nbsp;货&nbsp;&nbsp;人：<span th:text="${delivery.consignee}"></span></div>
				  <div class="col-sm-6">联系电话：<span th:text="${delivery.tel}"></span></div>
				</div>
				<div class="row">
				  <div class="col-sm-6">收货地址：<span th:text="${delivery.orderAddress}"></span></div>
				</div>
			</div>
		</div>
        <input type="hidden" id="ordersId" th:value="${delivery.ordersId}">
        <span style="margin: 20px 0 0 45%;" class="print" onclick="delivery()">发货</span>

	<th:block th:include="include :: footer" />
	<script th:src="@{/js/plugins/chosen/chosen.jquery.js}"></script>
	<script th:inline="javascript">
		var logisticsName;
		var prefix = ctx + "core/orders";
		$(function() {
				$(".chosen-select").chosen({
					maxHeight : 200
				});
				$('.chosen-select').on('change', function(e, params) {
					logisticsName = params.selected;
				});
		});
		// 发货
		function delivery(){
			var number = $('#number').val();
			if(number == ''){
				layer.msg('请填写物流单号!');
				return;
			}

			if(logisticsName == null || logisticsName== ''){
				layer.msg('请选择物流公司!');
				return;
			}
			$.operate.save(prefix + "/delivery",{
				'ordersId' : $('#ordersId').val(),
				'expressNumber' : number,
				'logisticsName':logisticsName
			});
		}

		//  通过物流单号查询物流公司和物流编码
		function KdApiOrderDistinguish(obj){
			var expNo = $(obj).val();
			if(expNo == ''){
				return;
			}
			$.ajax({
				url : prefix + "/KdApiOrderDistinguish/" + expNo,
				type : "get",
				success : function(data) {
					//该物流码是否有误
					if (data.code == 0) {
						layer.alert('该单号的快递为:'+data.msg);
						$('.chosen-single span').text(data.msg);
						logisticsName = data.msg;
					}else {
						layer.alert(data.msg);
					}
				}
			});
		}
	</script>
</body>
</html>